<?php

class AnswerModel extends Model {
	// 制定本类操作的表名
	public $table = '360_ans';

	// 得到答案表有关的信息以及分页信息
	public function AllAnswer(){
		// 得到总条数
		$Count = $this->count();
		// 实例化分页类,每页显示10条数据
		$PageInfo = new Page($Count,10);
		// 得到页码
		$Page = $PageInfo->show_b();
		// 得到limit语句所需数量
		$Limit = $PageInfo->limit();
		// 获取所有记录
		$Ans = $this->order("ans_id DESC")->limit($Limit)->select();
		// 返回结果
		return array('count'=>$Count,'Pages'=>$Page,'Ans'=>$Ans);
	}
	// 未采纳回答
	public function NoAcceptAnswer(){
		// 获取所有未采纳答案记录数的SQL语句
		$CSql = "SELECT COUNT(*) AS count FROM 360_ans AS ans
		LEFT JOIN
		360_accept AS accept 
		ON ans.ans_id = accept.ans_id
		WHERE id IS NULL
		ORDER BY id";
		// 执行查询语句
		$Count = $this->query($CSql);
		// 实例化分页类 分配每页显示数量
		$PageInfo = new Page($Count[0]['count'],10);
		// 获得页码
		$Page = $PageInfo->show_b();
		// 获得LIMIT 语句所需数字
		$Limit = $PageInfo->limit();
		// 查询未采纳答案的SQL
		$Sql = "SELECT ans.ans_content,ans.ans_time FROM 360_ans AS ans
		LEFT JOIN
		360_accept AS accept 
		ON ans.ans_id = accept.ans_id
		WHERE id IS NULL ORDER BY ans.ans_id DESC LIMIT {$Limit}";
		// 执行查询语句获得所有未采纳答案列表
		$Field = $this->query($Sql);
		return array('count'=>$Count[0]['count'],'Pages'=>$Page,'Field'=>$Field);
	}
	// 获取已采纳答案记录
	public function AcceptAnswer(){
		// 获得已采纳答案记录数的SQL语句
		$CSql = " SELECT COUNT(*) AS count FROM 360_ans AS ans
		JOIN
		360_accept AS accept 
		ON ans.ans_id = accept.ans_id
		ORDER BY id ";
		// 执行查询语句
		$Count = $this->query($CSql);
		// 实例化分页类
		$PageInfo = new Page($Count['0']['count'],10);
		// 获取页码
		$Pages = $PageInfo->show_b();
		// 获取LIMIT语句所需数字
		$Limit = $PageInfo->limit();
		// 获取已采纳答案列表的SQL语句
		$Sql = "SELECT * FROM 360_ans AS ans
		JOIN
		360_accept AS accept 
		ON ans.ans_id = accept.ans_id ORDER BY ans.ans_id DESC LIMIT {$Limit}";
		// 执行查询语句并获得已采纳答案
		$AnsList = $this->query($Sql);
		// 返回结果
		return array('count'=>$Count[0]['count'],'Pages'=>$Pages,'Field'=>$AnsList);

	}


}


?>